package Q1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static int n;
    public static List<Integer> list = new ArrayList<>();
    public static int[] nums;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt(); //身高为 1 - n
        nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }

        dfs(0, new boolean[n], new int[n]);

        for (int i : list) {
            System.out.print(i + " ");
        }
    }

    public static void dfs(int index, boolean[] flag, int[] arr) {

        if (!list.isEmpty()) {
            return;
        }

        if (index == n) {
            boolean flag1 = false;
            for (int i = 1; i < n - 1; i++) {
                if ((arr[i + 1] - arr[i]) * (arr[i] - arr[i - 1]) > 0) {
                    flag1 = true;
                    break;
                }
            }
            if (!flag1) {
                for (int i = 0; i < n; i++) {
                    list.add(arr[i]);
                }
            }

            return;
        }

        for (int i = 0; i < n; i++) {
            if (!flag[i]) {
                flag[i] = true;
                arr[index] = nums[i];
                dfs(index + 1, flag, arr);

                //回溯
                flag[i] = false;
                arr[index] = 0;
            }
        }
    }
}
